package com.java.pay.controller;


import com.java.common.vo.R;
import com.java.pay.entity.PaymentInfo;
import com.java.pay.service.PaymentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jiangli
 * @since 2019-12-15
 */
@RestController
@RequestMapping("/pay")
public class PaymentInfoController {
	@Autowired
	private PaymentInfoService paymentInfoService;

	/**
	 * 创建支付交易信息
	 * postman模拟请求
	 {
	 "typeId":"1",
	 "orderId":"1102203300",
	 "price":"100",
	 "source":"1",
	 "state":"0"
	 }
	 */
	@PostMapping("/addPayInfoToken")
	public R addPaymentInfo(@RequestBody PaymentInfo paymentInfo) {
		return paymentInfoService.addPaymentInfo(paymentInfo);
	}

	/**
	 * 通过token查询支付信息
	 */
	@GetMapping("/getPayInfoToken")
	public ResponseEntity<PaymentInfo> getPayInfoByToken(@RequestParam("token")String token){
		return paymentInfoService.getPayInfoByToken(token);
	}

	/**
	 * 使用订单id查询支付信息
	 */
	@GetMapping("/getByOrderIdPayInfo")
	public ResponseEntity<PaymentInfo> getPayInfoByOrderId(@RequestParam("orderId") String orderId){
		return paymentInfoService.getPayInfoByOrderId(orderId);
	}

	/**
	 * 修改支付信息
	 */
	@PostMapping("/updatePayInfo")
	public R updatePayInfo(@RequestBody PaymentInfo paymentInfo){
		return paymentInfoService.updatePayInfo(paymentInfo);
	}

}

